package com.wedo.mall.adapter;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.e.library.adapter.Adapter;
import com.wedo.mall.R;
import com.wedo.mall.entity.Comment;
import com.wedo.mall.util.DateUtils;
import com.wedo.mall.util.WUrl;
import com.wedo.mall.widget.GridImage;
import com.wedo.mall.widget.StarView;

import java.text.SimpleDateFormat;
import java.util.List;

/**
 * Created by e on 2017/7/9.
 */

public class CommentAdapter extends Adapter<Comment> {

    private SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
    String goods_comment_reply;

    public CommentAdapter(Context context, List<Comment> datas) {
        super(context, datas);
        goods_comment_reply = context.getResources().getString(R.string.goods_comment_reply);
    }

    @Override
    protected int layout() {
        return R.layout.item_comment;
    }

    @Override
    protected void bind(EHolder holder, Comment comment, int position) {
        ImageView iv_comment_img = holder.find(R.id.iv_comment_img);
        TextView tv_comment_nickname = holder.find(R.id.tv_comment_nickname);
        StarView sv_comment_star = holder.find(R.id.sv_comment_star);

        TextView tv_comment_context = holder.find(R.id.tv_comment_context);
        GridImage gi_image = holder.find(R.id.gi_comment_image);
        TextView tv_comment_time = holder.find(R.id.tv_comment_time);
        TextView tv_reply_content = holder.find(R.id.tv_reply_content);

        tv_comment_nickname.setText(comment.nickname);
        tv_comment_context.setText(comment.contain);
        sv_comment_star.star(comment.star);
        gi_image.image(comment.images);

        StringBuilder sb = new StringBuilder();
        sb.append(DateUtils.convert(format,comment.add_time)).append(" ").append(comment.attr_list);
        tv_comment_time.setText(sb.toString());
        if (TextUtils.isEmpty(comment.reply_contain)){
            tv_reply_content.setText("");
            tv_reply_content.setVisibility(View.GONE);
        }else {
            tv_reply_content.setText(String.format(goods_comment_reply,comment.reply_contain));
            tv_reply_content.setVisibility(View.VISIBLE);
        }

        String img = WUrl.url(comment.headimgurl);
        Glide.with(mContext).load(img)
                .error(R.drawable.ease_default_avatar)
                .placeholder(R.drawable.ease_default_avatar)
                .diskCacheStrategy(DiskCacheStrategy.ALL).into(iv_comment_img);

    }
}
